<?php

/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

/**
 * Description of ProvinceLogic
 *
 * @author Administrator
 */
class ProvinceLogic extends BaseLogic{
    //put your code here
    private $provinceTable;
    public function __construct() {
        parent::__construct();
        $this->provinceTable=  $this->load("Province");
        $this->table=  $this->provinceTable;
    }
    /**
     * 
     * @return type获得所有省份
     */
    public function getAllProvince(){
        $res=  $this->provinceTable->select("*");
        return $res;
    }
    /**
     * 通过省份编码获得省份信息
     * @param type $code省份编码
     */
    public function getProvinceByCode($code){
        $res=  $this->provinceTable->get_one("*", "provinceID='{$code}'");
        return $res;
    }
    /**
     * 通过区域id获得省份信息
     * @param type $id 省份id
     * @return boolean 省份信息
     */
    public function getProvinceInfoById($id){
         if($id){
            $res=  $this->provinceTable->get_one("*","id={$id}");
            return $res;
        }
        return FALSE;
    }
    /**
     * 通过省份名称获得id
     * @param type $name 省份名称
     * @return int  省份id
     */
    public function getIdByName($name){
        if($name){
            $res=  $this->provinceTable->get_one("*","province like '{$name}%'");
            return $res["id"];
        }
        return 0;
    }
     /**
     *    保存和更新省份列表
     * @param type $data 省份信息
     * @param type $id   省份id
     * @return type  
     */
    public function save($data,$id=0){
        if($id>0){
            $res=  $this->provinceTable->update($data,"id={$id}");
        }else{
            $res=$this->provinceTable->insert($data,TRUE);
        }
        return $res;
    }
}
